package com.superbytecode.stencil.entities;

import lombok.Data;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: code-stencil
 * @Package: com.superbytecode.stencil.entities.res
 * @ClassName: WebResult
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/10/11 19:39
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.cn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Data

public class WebResult<T> {
    /**
     * 响应编码
     */
    private String code;
    /**
     * 响应消息
     */
    private String msg;
    /**
     * 响应数据
     */
    private T data;
    // -----------------------------------------------------------------------------------------------------------------
    private static final String CODE_SUCCESS = "200";
    private static final String CODE_ERROR = "500";

    public static <T> WebResult<T> success() {
        return success(null);
    }

    public static <T> WebResult<T> success(T data) {
        WebResult<T> result = new WebResult<T>();
        result.setCode(CODE_SUCCESS);
        result.setData(data);
        return result;
    }

    public static <T> WebResult<T> failure(String msg) {
        WebResult<T> result = new WebResult<T>();
        result.setCode(CODE_ERROR);
        result.setMsg(msg);
        return result;
    }
}